package ca.qc.bdeb.info.pp2.tp2.application;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

public class AgentDAO
{
    public static List<Agent> listerAgent()
    {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        Query query = session.createQuery("from Agent where actif = 1 and poste = 'Agent' order by nom");

        return (List<Agent>) (query.list());
    }

    public static List<Agent> listerAgent(String prenom, String nom, String codePostal)
    {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        Query query = session.createQuery("from Agent where actif = 1 and poste = 'Agent' "
                + "and upper(prenom) like '%" + prenom.toUpperCase() + "%' and upper(nom) like '%" + nom.toUpperCase() + "%'"
                + "and upper(code_postal) like '%" + codePostal.toUpperCase() +"%' "
                + "order by nom");

        return (List<Agent>) (query.list());
    }
}
